package com.zwz.controller;


import com.github.pagehelper.PageInfo;
import com.zwz.crawler.annualReports.TungReportsEmail;
import com.zwz.crawler.annualReports.TungYearReport;
import com.zwz.crawler.annualReports.TungeeAnnualReportQuery;
import com.zwz.crawler.basic.*;
import com.zwz.crawler.knowledge.TungKnowledge;
import com.zwz.crawler.main.TungeeLeadsQuery;
import com.zwz.crawler.mangeInfo.TungeeCourtCaseQuery;
import com.zwz.crawler.mangeInfo.TungeeLicenseQuery;
import com.zwz.crawler.mangeInfo.invertPage.TungeeInvestmentQuery;
import com.zwz.crawler.mangeInfo.weburl.StrictTungeeRequest;
import com.zwz.crawler.productdata.TungeeSoftwareQuery;
import com.zwz.crawler.riskInfo.JsoupLimit;
import com.zwz.crawler.riskInfo.JsoupRiskRequest;
import com.zwz.crawler.riskInfo.JsoupTaxpayerRequest;
import com.zwz.crawler.tendering.getBigInfo.TungeeBiddingSearch;
import com.zwz.entity.*;
import com.zwz.service.*;
import com.zwz.vo.*;
import com.zwz.voObject.*;
import com.zwz.voObject.EnterpriseDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.zwz.constant.Constant.MILLIS_MAIN;


@Slf4j
@RestController
@RequestMapping("/api/enterprises")
public class EnterpriseController {


    private final EnterpriseService enterpriseService;

    @Autowired
    private InvestmentEmploymentService service;

    @Autowired
    private EnterpriseAnnualReportService annualReportService;


    @Autowired
    private InformationChangeService changeservice;


    @Autowired
    private AgentAccountInfoService telservice;


    @Autowired
    private OfficialWebsiteInfoService officialWebsiteInfoService;


    @Autowired
    private CompanyOperationStatusService companyOperationStatusService;


    @Autowired
    private QualificationService qualificationService;


    @Autowired
    private BusinessAbnormalityService businessAbnormalityService;


    @Autowired
    private AdministrativePenaltyService administrativePenaltyService;


    @Autowired
    private CourtAnnouncementService courtAnnouncementService;


    @Autowired
    private JudgmentDocumentService JudgementService;


    @Autowired
    private DishonestPersonService dishonestPersonService;


    @Autowired
    private TerminatedCaseService terminatedCaseService;


    @Autowired
    private ConsumptionRestrictionService restrictionService;


    @Autowired
    private BankruptcyReorganizationService bankruptcyService;


    @Autowired
    private  TaxpayerQualiService  taxpayerQualiService;


    @Autowired
    private TrademarkService trademarkService;



    @Autowired
    private SoftwareRegistryService  softwareRegistryService;



    @Autowired
    private ExecutedPersonService executedPersonService;



    public EnterpriseController(EnterpriseService enterpriseService) throws InterruptedException {
        this.enterpriseService = enterpriseService;
    }

    /**
     *子页面	主表基本信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<EnterpriseInfo> getEnterprise(@PathVariable Long id) {
        EnterpriseInfo enterprise = enterpriseService.getById(id);
        return ResponseEntity.ok(enterprise);
    }

    @GetMapping
    public ResponseEntity<List<EnterpriseInfo>> getAllEnterprises() {
        return ResponseEntity.ok(enterpriseService.getAll());
    }


    //todo 还需要加上事务

    /**
     * 断点爬取逻辑：
     * //1.启动扫描主表标识位如果是null 继续爬取，证明该条记录是新的，
     * 如果是0，获取对应的记录，删除该条的对应的主键记录的所有记录，按照爬取逻辑重新爬取。
     * 如果是1，跳过该条逻辑。
     *
     * //2.其中任意一个子表数据插入失败，标识为对应的0，数据爬取成功是1
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
    @PostMapping
    public ResponseEntity<EnterpriseInfo> createEnterprise() throws IOException, InterruptedException {
        log.info("=======================================数据爬取开始====================================");

        List<String> list = TungeeLeadsQuery.getTotalRecotd();
        for(int i=0;i<list.size();i++){
            getEnterpriseInfo(list.get(i));
        }
        log.info("=======================================数据爬取结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(null);
    }


    /**
     *  子程序嵌套的方法类
     * @param enterpriseId
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
    private EnterpriseInfo getEnterpriseInfo(String enterpriseId) throws IOException, InterruptedException {


        //1.调用解析层数据入库即可
        MemInfo bean = TungeeMemberQuery.startTungeeMemberQuery(enterpriseId);

        //2.获取认缴出资日期,实缴资本必须放在前面
        EnterpriseInfo enterprise = TungeeEnterpriseInfo.startTungeeEnterpriseInfo(enterpriseId);

        //3.国有企业的和曾用名方法
//        enterprise.set

        //3.调用入库,获取主键
        if (StringUtils.isEmpty(enterprise.getCompanyName())) {
            enterprise.setCompanyName("未知");
        }
        if (null == enterprise.getEstablishDate()) {
            enterprise.setEstablishDate(LocalDate.now());
        }

        int rows = enterpriseService.create(enterprise);

        int pk = 0;
// 验证主键
        if (rows > 0) {
            log.info("插入成功，主键ID: " + enterprise.getId());
            pk = Math.toIntExact(enterprise.getId());
        } else {
            log.info("插入失败");
        }

        //3.1 在这里的进行相关连接表的数据更新

        //3.1.1  插入对应的投资任职信息

        MemInfo bean1 = TungeeMemberQuery.startTungeeMemberQuery(enterpriseId);
        InvestmentEmploymentInfo invert = TungeeBranchOfficeQuery.startTungeeBranchOfficeQuery(enterpriseId);

        int data = TungeeInvestmentQuery.StartTungeeInvestmentQuery(enterpriseId);
        if (invert != null) {
            //reset
            if (null == bean1 || StringUtils.isEmpty(bean1.getSholdnum())) {
                log.error("对象是空的");
            } else {
                invert.setShareholderCount(Integer.parseInt(bean1.getSholdnum()));
                invert.setLargestShareholderRatio(bean1.getMaxShold());
                invert.setEnterpriseId(pk);
                service.create(invert);
            }


            if (data == 0) {
                invert.setHasForeignInvestment(Boolean.FALSE);
            }
        } else {
            log.error("invert  object is null");
        }


        //3.1.2  插入对应的年报信息
        List<ReportInfo> reports = TungYearReport.startTungeeAnnualReportQuery(enterpriseId);
        List<EnterpriseAnnualReport> info = TungeeAnnualReportQuery.startTungeeAnnualReportQuery(enterpriseId);


        int data1 = TungeeInvestmentQuery.StartTungeeInvestmentQuery(enterpriseId);

        if (null == reports) {

            log.info("parse report is nulll");

        } else {
            for (int i = 0; i < reports.size(); i++) {
                //1. 从中间层收取
//            info.get(i).setNetProfit(new BigDecimal(reports.get(0).getNetSum()));
                //在这里进行转义

//                info.get(i).setTotalRevenue(new BigDecimal(reports.get(i).getAboundSum()));
//                info.get(i).setTaxAmount(new BigDecimal(reports.get(i).getTaxSum()));
//                info.get(i).setTotalProfit(new BigDecimal(reports.get(i).getPureprofit()));


                if (org.springframework.util.StringUtils.isEmpty(reports.get(i).getAboundSum())
                        && org.springframework.util.StringUtils.isEmpty(reports.get(i).getTaxSum())
                        && org.springframework.util.StringUtils.isEmpty(reports.get(i).getPureprofit())
                ) {


// 修复后（处理 null 和无效值）
                    BigDecimal value1 = (reports.get(i).getAboundSum() != null && !reports.get(i).getAboundSum().isEmpty())
                            ? new BigDecimal(reports.get(i).getAboundSum())
                            : BigDecimal.ZERO; // 默认 0

                    BigDecimal value2 = (reports.get(i).getAboundSum() != null && !reports.get(i).getTaxSum().isEmpty())
                            ? new BigDecimal(reports.get(i).getAboundSum())
                            : BigDecimal.ZERO; // 默认 0

                    BigDecimal value3 = (reports.get(i).getAboundSum() != null && !reports.get(i).getPureprofit().isEmpty())
                            ? new BigDecimal(reports.get(i).getAboundSum())
                            : BigDecimal.ZERO; // 默认 0

                    info.get(i).setTotalRevenue(value1);
                    info.get(i).setTotalRevenue(value2);
                    info.get(i).setTotalRevenue(value3);


//                    info.get(i).setTotalRevenue(new BigDecimal("选择不".equals(reports.get(i).getAboundSum()) ? "0.0" : reports.get(i).getAboundSum()));
//                    info.get(i).setTaxAmount(new BigDecimal("选择不".equals(reports.get(i).getTaxSum()) ? "0.0" : reports.get(i).getTaxSum()));
//                    info.get(i).setTotalProfit(new BigDecimal("选择不".equals(reports.get(i).getPureprofit()) ? "0.0" : reports.get(i).getPureprofit()));
                } else {
                    log.error("数据不合法，以后优化");
                }

//             info.get(i).setHasReport();

                if (data1 == 0) {
                    info.get(i).setForeignInvestment("false");
                } else {
                    info.get(i).setForeignInvestment("true");
                }
                info.get(i).setEnterpriseId(pk);
                annualReportService.create(info.get(i));
            }


        }


        //3.1.3  插入变更信息
        List<InformationChange> changelist = TungeeAlterationQuery.startTungeeAlterationQuery(enterpriseId);
        if (null != changelist && changelist.size() > 0) {
            for (int i = 0; i < changelist.size(); i++) {
                changelist.get(i).setEnterpriseId(pk);
                changeservice.create(changelist.get(i));
            }

        } else {
            log.error("获取变更集合空");
        }


        //3.1.4 插入联系方式信息

        AccountInfo email = TungReportsEmail.startTungeeAnnualReportQuery(enterpriseId);
        AgentAccountInfo record = new AgentAccountInfo();
        if (email != null) {
            record.setMobile(email.getTel());
            record.setEmail(email.getEmail());
            record.setLandline(email.getLandline());
            record.setEnterpriseId(pk);
            telservice.create(record);
        } else {
//            System.err.println("email is null");
            log.error("获取的联系方式信息为空");
        }


        //3.1.5  插入官网信息
        OfficialWebsiteInfo info2 = TungeeEnterpriseInfo_weburl.startTungeeEnterpriseInfo(enterpriseId);

        WebUrl bean2 = StrictTungeeRequest.StartStrictTungeeRequest(enterpriseId);
        if (null != info2) {
            info2.setIpPhysicalLocation(bean2.getLcoation());
            info2.setIcpRecordDate(bean2.getTime());
            info2.setIpOperationNode(bean2.getNode());
            info2.setEnterpriseId(pk);
            officialWebsiteInfoService.create(info2);
        } else {

        }


        //3.1.6  插入企业状态信息
        //1.2 请求聚合对应的招投标信息
//          winlist = TungeeWinningStats.startTungeeWinningStats(); 没有使用

        List<BidInfo> bean3 = TungeeBiddingSearch.startTungeeBiddingSearch(enterpriseId);
        if (null != bean3 && bean3.size() > 0) {
            CompanyOperationStatus record3 = null;
            for (int i = 0; i < bean3.size(); i++) {

                //2.获取对应返回的解析bean

                record3 = new CompanyOperationStatus();
                record3.setBiddingTitle(bean3.get(i).getTitile());
                record3.setBiddingPublishDate(bean3.get(i).getTime());
                record3.setBiddingNoticeType(bean3.get(i).getType());
//            record.setBiddingNoticeType(bean.get(i).getB);

                record3.setCreatedAt(new Date());
                record3.setUpdatedAt(new Date());
                record3.setEnterpriseId(pk);
                companyOperationStatusService.create(record3);
            }
        } else {
            log.error("获取的bean 实体为空");
        }


        //3.1.7  插入资质证书
        //1.获取的对应的行政许可
        List<LicVo> lic = TungeeLicenseQuery.LicenseInfo(enterpriseId);

        //2.获取对应的纳税人信息


        //2.获取对应的税务登记
        QualificationCertificates cert = new QualificationCertificates();

        if (null != lic && lic.size() > 0) {
            //构建一个新的目的
            for (int i = 0; i < lic.size(); i++) {
                cert.setLatestPublishDate(lic.get(i).getStart());
                cert.setLicenseContent(lic.get(i).getContent());
                cert.setLicenseStartDate(lic.get(i).getStart());
                cert.setLicenseEndDate(lic.get(i).getEnd());
                cert.setLicenseAuthority(lic.get(i).getGov());
                cert.setLicenseContent(lic.get(i).getContent());
                cert.setLicenseFileName(lic.get(i).getName());
                cert.setEnterpriseId(pk);           //必须挂接主键
                qualificationService.save(cert); //
            }
        } else {
            log.error("获取的lic为空");
        }


        //以下为对应的企业风险信息,一个主表

        //3.1.8 经营异常
        List<BusinessAbnormality> list = JsoupRiskRequest.startJsoupRiskRequest(enterpriseId);
        Boolean flag=false;
        BusinessAbnormality data4 = new BusinessAbnormality();
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                data4.setAbnormalityCount(list.get(i).getAbnormalityCount());
                data4.setHistoricalReasons(list.get(i).getRemovalReasons());
                data4.setLatestInclusionDate(list.get(i).getLatestInclusionDate());
                data4.setRemovalReasons(list.get(i).getRemovalReasons());
                data4.setHasAbnormality(true); //记录大于0了，有异常了肯定是true
                // 4. 插入子表数据
                businessAbnormalityService.createWithMain(String.valueOf(pk),data4);

            }


            //3.1.9 行政处罚
            administrativePenaltyService.createWithMain(String.valueOf(pk));

//        3.1.10 法院公告

            List<CourtAnnouncement> datalist = TungeeCourtCaseQuery.startGetCourtInfo(enterpriseId);
            CourtAnnouncement announcement=null;
            int k=0;
            for(int i=0;i<datalist.size();i++){
                announcement=new CourtAnnouncement();
                announcement.setHasCourtSession(datalist.get(i).getHasCourtSession());
                announcement.setAnnouncementDate(datalist.get(i).getSessionDate());
                announcement.setAnnouncementType(datalist.get(i).getAnnouncementType());
                announcement.setSessionCount(datalist.size());
                announcement.setSessionReason(datalist.get(i).getSessionReason());
                announcement.setCaseNumber(datalist.get(i).getCaseNumber());
                announcement.setSessionDate(datalist.get(i).getSessionDate());
                courtAnnouncementService.createWithMain(String.valueOf(pk),announcement);
            }




            //3.1.11 裁判文书
            JudgementService.createWithMain(String.valueOf(pk));
            //3.1.12 失信被执行人不是被执行人，后台数据为空，无法获取对应的接口ulr 供爬取

            dishonestPersonService.createWithMain(String.valueOf(pk));


//   3.1.13     插入终本案件
            terminatedCaseService.createWithMain(String.valueOf(pk));
//   3.1.14             插入限制高消费
            restrictionService.createWithMain(String.valueOf(pk));

//  3.1.15      插入破产重整
            bankruptcyService.createWithMain(String.valueOf(pk));



//            3.1.16  考虑到指标的计算增加一个对应的tb_taxpayer_quali的计算入库库
            TaxpayerQuali b1=null;
          List<TaxpayerQuali> taxinfo = JsoupTaxpayerRequest.startJsoupTaxpayerRequest(enterpriseId);
         if(taxinfo!=null && taxinfo.size()>0){
             for(int i=0;i<taxinfo.size();i++){
                 b1=new TaxpayerQuali();
                 b1.setName(taxinfo.get(i).getName());
                 b1.setEndDate(taxinfo.get(i).getEndDate());
                 b1.setStartDate(taxinfo.get(i).getStartDate());
                 b1.setCertType(taxinfo.get(i).getCertType());
                 taxpayerQualiService.create(b1,String.valueOf(pk));
             }

         }


         //3.1.17 开始入商标库
            Trademark bean17=null;
            List<Trademark> data5 = TungKnowledge.startTungKnowledge(enterpriseId);
//           int pk17=0;
           if(null!=data5 && data5.size()>0){
               for(int i=0;i<data5.size();i++){
                   bean17 = data5.get(i);
//                   bean17.setId(pk17++);
                   this.trademarkService.createTrademark(bean17,String.valueOf(pk));

               }

           }else{
               log.error("请注意获取的商标信息是空的");
           }



           //3.1.18
            SoftwareRegistry bean18=null;
            List<SoftwareRegistry> data6 = TungeeSoftwareQuery.startTungeeSoftwareQuery(enterpriseId);
//            int pk18=0;
            if(null!=data6 && data6.size()>0){
                for(int i=0;i<data6.size();i++){
                    bean18 = data6.get(i);
//                    bean18.setId(pk18++);
                    this.softwareRegistryService.create(bean18,String.valueOf(pk));
                }

            }else{
                log.error("请注意获取的商标信息是空的");
            }



            //3.1.19 入库对应的executePerson
            ExecutedPerson bean19=null;
            List<ExecutedPerson> data19 = JsoupLimit.startJsoupRiskRequest(enterpriseId);
            if(data19!=null){
                if(data19.size()>0){
                    for (int i=0;i<data19.size();i++){
                        bean19=data19.get(i);
                        this.executedPersonService.createWithMain(bean19,String.valueOf(pk));
                    }
                }else{
                    log.error("请注意执行人是空的");
                }

            }else{
                log.error("返回的执行人集合是空的");
            }



            Thread.sleep(MILLIS_MAIN);


        }
        return enterprise;
    }

    @PutMapping("/{id}")
    public ResponseEntity<Void> updateEnterprise(@PathVariable Long id,
                                                 @RequestBody EnterpriseInfo enterprise) {
        enterprise.setId(id);
        enterpriseService.update(enterprise);
        return ResponseEntity.noContent().build();
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteEnterprise(@PathVariable Long id) {
        enterpriseService.delete(id);
        return ResponseEntity.noContent().build();
    }




    // ... existing code ...

    @GetMapping("/{id}/detail")
    public ResponseEntity<EnterpriseDetailVO> getEnterpriseDetail(@PathVariable Long id) {
        EnterpriseDetailVO detailVO = new EnterpriseDetailVO();

        // 获取主表信息
        EnterpriseInfo enterprise = enterpriseService.getById(id);
        detailVO.setEnterpriseInfo(enterprise);

        // 获取投资任职信息
        InvestmentEmploymentInfo investmentInfo = service.getById(Math.toIntExact(id));
        detailVO.setInvestmentEmploymentInfo(investmentInfo);

        // 获取年报信息 ，这个确实shilist,这个聚合youhua
//        List<EnterpriseAnnualReport> annualReports = annualReportService.getById(Math.toIntExact(id));
//        detailVO.setAnnualReports(annualReports);

        // 获取变更信息
         InformationChange  changes = changeservice.getById(Math.toIntExact(id));
        detailVO.setInformationChanges(changes);

        // 获取代理记账信息
        AgentAccountInfo  accountInfos = telservice.getById(Math.toIntExact(id));
        detailVO.setAgentAccountInfos(accountInfos);

        // 获取官网信息
        OfficialWebsiteInfo  websiteInfos = officialWebsiteInfoService.getById(Math.toIntExact(id));
        detailVO.setOfficialWebsiteInfos(websiteInfos);

        // 获取经营状态信息
       CompanyOperationStatus  operationStatuses = companyOperationStatusService.getById(Math.toIntExact(id));
        detailVO.setOperationStatuses(operationStatuses);

        // 获取资质信息
        QualificationCertificates qualifications = qualificationService.getById(Math.toIntExact(id));
        detailVO.setQualifications(qualifications);

        // 获取经营异常信息
        BusinessAbnormality abnormalities = businessAbnormalityService.getAbnormalityById(Math.toIntExact(id));
        detailVO.setBusinessAbnormalities(abnormalities);

        // todo 获取行政处罚信息.需要增加
//        AdministrativePenalty  penalties = administrativePenaltyService.(id);
//        detailVO.setAdministrativePenalties(penalties);

        //todo 获取行政处罚信息.需要增加 获取法院公告信息
//        CourtAnnouncement announcements = courtAnnouncementService.getById(id);
//        detailVO.setCourtAnnouncements(announcements);

        // 获取裁判文书信息todo 带以后测试
//        JudgmentDocument documents = JudgementService.getById(id);
//        detailVO.setJudgmentDocuments(documents);
//
//        // 获取失信人信息
//        DishonestPerson  dishonestPersons = dishonestPersonService.getById(id);
//        detailVO.setDishonestPersons(dishonestPersons);
//
//        // 获取终本案件信息
//        TerminatedCase terminatedCases = terminatedCaseService.getById(id);
//        detailVO.setTerminatedCases(terminatedCases);

        // 获取限制消费信息
        List<ConsumptionRestriction> restrictions = restrictionService.getByCaseNumber(String.valueOf(id));
        detailVO.setConsumptionRestrictions(restrictions);


        // 获取纳税人资质信息
        TaxpayerQuali  taxpayerQualis = taxpayerQualiService.getById(Math.toIntExact(id));
        detailVO.setTaxpayerQualis(taxpayerQualis);

        return ResponseEntity.ok(detailVO);
    }



    //提出一个对应的控制器接口

    /**
     * 分页获取对应的企业主信息，可以按照名称查询，否则默认查全部
     * 分页获取对应的企业主信息，可以按照名称查询，否则默认查全部
     * 主界面接口查询
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return 分页结果
     */
    /**
     * 分页获取对应的企业主信息，可以按照名称查询，否则默认查全部
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return 分页结果
     */
    @PostMapping("/getCompanyInfoList")
    public ResponseEntity<PageInfo<EnterpriseBean>> getCompanyInfoList(
            @RequestParam(defaultValue = "") String companyName,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("=======================================获取主信息开始====================================");
        log.info("页码: {}, 每页大小: {}", pageNum, pageSize);

        //MD，，缓存字节码文件编译失败，
        PageInfo<EnterpriseBean> data = this.enterpriseService.getEnterpriseBeanPage(pageNum, pageSize, companyName);

        log.info("=======================================获取主信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(data);
    }


    //提供对应的确定的四个字段进行确定接口的代码编写company_profile，establish_date，registered_address，company_type

    /**
     * 根据企业类型模糊查询分页获取对应的企业主信息
     * 主界面接口查询
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return 分页结果
     */
    @PostMapping("/getCompanyInfoByType")
    public ResponseEntity<PageInfo<EnterpriseBean>> getCompanyInfoByType(
            @RequestParam(defaultValue = "") String companyType,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("=======================================获取主信息开始====================================");
        log.info("页码: {}, 每页大小: {}", pageNum, pageSize);

        //MD，，缓存字节码文件编译失败，
        PageInfo<EnterpriseBean> data = this.enterpriseService.getEnterpriseBeanPageByCompanyType(pageNum, pageSize, companyType);

        log.info("=======================================获取主信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(data);
    }


    /**
     * 根据企业日期区间查询分页获取对应的企业主信息
     * 主界面接口查询
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return 分页结果
     */
    @PostMapping("/getCompanyInfoByDate")
    public ResponseEntity<PageInfo<EnterpriseBean>> getCompanyInfoByDate(
            @RequestParam(defaultValue = "") String startDate,
            @RequestParam(defaultValue = "") String endDate,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("=======================================获取主信息开始====================================");
        log.info("页码: {}, 每页大小: {}", pageNum, pageSize);

        //MD，，缓存字节码文件编译失败，
        PageInfo<EnterpriseBean> data = this.enterpriseService.getEnterpriseBeanPageByDate(pageNum, pageSize, startDate, endDate);

        log.info("=======================================获取主信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(data);
    }


    /**
     * 根据企业营业状态模糊查询分页获取对应的企业主信息
     * 主界面接口查询，企业经营状态的专业问题，这里就简单取值
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return 分页结果
     */
    @PostMapping("/getCompanyInfoByStatus")
    public ResponseEntity<PageInfo<EnterpriseBean>> getCompanyInfoByStatus(
            @RequestParam(defaultValue = "") String businessStatus,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("=======================================获取主信息开始====================================");
        log.info("页码: {}, 每页大小: {}", pageNum, pageSize);
        //MD，，缓存字节码文件编译失败，
        PageInfo<EnterpriseBean> data = this.enterpriseService.getEnterpriseBeanPageByStatus(pageNum, pageSize, businessStatus);

        log.info("=======================================获取主信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(data);
    }


//    提出一个对应的控制器接口,按照右表

    /**
     * 公司发展
     * 获取对应的公司发展信息
     *
     * @param id
     * @return
     */
    @PostMapping("/getDevelopmentInfo")
    public ResponseEntity<List<CompanyStatus>> getDevelopmentInfo( String id)  {
        log.info("=======================================获取主信息开始====================================");

        List<CompanyStatus> list = this.companyOperationStatusService.getInfo(id);

        log.info("=======================================获取主信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(list);
    }



    /**
     *  获取对应的管理信息， 源数据设计不合理，异常只有1个
     * @param ids
     * @return
     */
    @PostMapping("/getMangeInfo")
    public ResponseEntity<MangeInfo> getMangeInfo( String ids)  {
        log.info("=======================================获取经营信息开始====================================");

        int id = Integer.parseInt(ids);
       MangeInfo res = this.businessAbnormalityService.getCurrentAbnormalitiesMangeInfo(String.valueOf(id));

        log.info("=======================================获取经营信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(res);
    }


    /**
     *  获取对应的风险信息
     * @param ids
     * @return
     */
    @PostMapping("/getRiskInfo")
    public ResponseEntity<CourtCase> getRiskInfo( String ids)  {
        log.info("=======================================获取风险信息开始====================================");
        int id = Integer.parseInt(ids);
        CourtCase res = this.courtAnnouncementService.getCourseInfo(String.valueOf(id));

        log.info("=======================================获取风险信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(res);
    }


    /**
     *  获取对应的招投标信息，查询的是企业状态表
     * @param ids
     * @return
     */
    @PostMapping("/getBid")
    public ResponseEntity<List<Bid>> getBid( String ids)  {
        log.info("=======================================获取招投标信息开始====================================");
        int id = Integer.parseInt(ids);
        List<Bid> res = this.companyOperationStatusService.getBidInfo(String.valueOf(id));

        log.info("=======================================获取招投标信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(res);
    }


    /**
     *  获取对应的企业年报信息，
     * @param
     * @return
     */
    @PostMapping("/getAnnulInfo")
    public ResponseEntity<List<AnnulReport>> getAnnulInfo(@RequestParam  String id  )  {
        log.info("=======================================获取招投标信息开始====================================");
//        int id = Integer.parseInt(ids);
        List<AnnulReport> res = this.annualReportService.getAnnulReportInfo(String.valueOf(id));

        log.info("=======================================获取招投标信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(res);
    }




    /**
     *  获取对应的知识信息，
     * @param
     * @return
     */
    @PostMapping("/getKnow")
    public ResponseEntity<List<Know>> getKnow(@RequestParam  String id  )  {
        log.info("=======================================获取知识产权信息开始====================================");
//        int id = Integer.parseInt(ids);
//        List<AnnulReport> res = this.trademarkService.getAnnulReportInfo(String.valueOf(id));
        List<Know> res = this.trademarkService.getKnowInfo(id);

        log.info("=======================================获取知识产权信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(res);
    }


    /**
     *  获取对应的产品信息，
     * @param
     * @return
     */
    @PostMapping("/getProductInfo")
    public ResponseEntity<List<SoftwareRegistry>> getProductInfo(@RequestParam  String id  )  {
        log.info("======================================获取对应的产品信息开始====================================");
        List<SoftwareRegistry> res = this.softwareRegistryService.getBySoftwareRegistry(id);
        log.info("=======================================获取对应的产品信息结束====================================");
        return ResponseEntity.status(HttpStatus.CREATED).body(res);
    }

    /**
     * 逻辑值查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/boolean")
    public ResponseEntity<QueryResultVO> queryByBoolean(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("执行逻辑值查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryByBoolean(condition, pageNum, pageSize);
            Long total = enterpriseService.countByBoolean(condition);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("逻辑值查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }

    /**
     * 整数区间查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/integer")
    public ResponseEntity<QueryResultVO> queryByInteger(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("执行整数区间查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryByInteger(condition, pageNum, pageSize);
            Long total = enterpriseService.countByInteger(condition);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("整数区间查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }

    /**
     * 浮点数区间查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/float")
    public ResponseEntity<QueryResultVO> queryByFloat(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("执行浮点数区间查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryByFloat(condition, pageNum, pageSize);
            Long total = enterpriseService.countByFloat(condition);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("浮点数区间查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }

    /**
     * 字符串包含查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/string")
    public ResponseEntity<QueryResultVO> queryByString(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("执行字符串包含查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryByString(condition, pageNum, pageSize);
            Long total = enterpriseService.countByString(condition);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("字符串包含查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }

    /**
     * 日期区间查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/date")
    public ResponseEntity<QueryResultVO> queryByDate(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("执行日期区间查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryByDate(condition, pageNum, pageSize);
            Long total = enterpriseService.countByDate(condition);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("日期区间查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }

    /**
     * 枚举值查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/enum")
    public ResponseEntity<QueryResultVO> queryByEnum(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("执行枚举值查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryByEnum(condition, pageNum, pageSize);
            Long total = enterpriseService.countByEnum(condition);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("枚举值查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }

    /**
     * 通用查询接口
     * @param condition 查询条件
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
    @PostMapping("/query/general")
    public ResponseEntity<QueryResultVO> queryGeneral(
            @RequestBody QueryConditionVO condition,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam Integer type) {
        log.info("执行通用查询: {}", condition);
        try {
            List<Map<String, Object>> records = enterpriseService.queryGeneral(condition, pageNum, pageSize, type);
            Long total = enterpriseService.countGeneral(condition, type);
            return ResponseEntity.ok(QueryResultVO.success(records, total, pageNum, pageSize));
        } catch (Exception e) {
            log.error("通用查询失败", e);
            return ResponseEntity.ok(QueryResultVO.error("查询失败：" + e.getMessage()));
        }
    }








}